package shili.server.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import shili.entity.SysUser;
import shili.entity.SysUserMapper;
import shili.server.SysUserService;

import java.util.List;

/**
 * SysUserServiceImpl
 *
 * @author boy
 * @since 2023/10/18
 */
@Transactional
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Autowired // @Resource // 使用注解的方式将DAO层的Bean注入
    private SysUserMapper sysUserMapper;
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<SysUser> list(SysUser sysUser) {
        try {
            return sysUserMapper.list(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public boolean add(SysUser sysUser) {
        sysUserMapper.add(sysUser);

        int num = 5 / 0; // 模拟程序中抛出异常
        sysUserMapper.add(sysUser);
        return true;
    }

    public SysUserMapper getSysUserMapper() {
        return sysUserMapper;
    }
    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }

}
